package com.example.pucha_xian.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.pucha_xian.Class.CPoint;
import com.example.pucha_xian.R;
import com.example.pucha_xian.common.Ablum;
import com.example.pucha_xian.common.CoordinateBean;
import com.example.pucha_xian.common.MapUtil;
import com.example.pucha_xian.common.PositionConvertUtil;
import com.example.pucha_xian.common.UserUtil;

public class WorkActivity extends BaseActivity {
    private ImageView iv_yj;
    private ImageView iv_zj;
    private ImageView iv_jj;
    private TextView tv_pointID;
    private TextView tv_name;
    private TextView tv_status;
    private Button btn_zpb;
    private Button btn_nav;
    private CPoint Point;
    private double lat;
    private double lng;
    private String token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_work);
        initView();
        Bundle bundle = getIntent().getExtras();
        lat=bundle.getDouble("lat");
        lng=bundle.getDouble("lng");
        Point = (CPoint) bundle.getSerializable("cpoint");
        if(Point.getPanorama() != null && !Point.getPanorama().equals("")){
            Glide.with(this).load(UserUtil.address+Point.getPanorama()).into(iv_yj);
            Glide.with(this).load(UserUtil.address+Point.getBust()).into(iv_zj);
            Glide.with(this).load(UserUtil.address+Point.getCloseup()).into(iv_jj);
        }
        tv_pointID.setText(Point.getPointID());
        tv_name.setText(Point.getName());
        tv_status.setText(Point.getStatus());
        btn_nav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                double lat, lng;
                lng = Point.getLng();
                lat = Point.getLat();

                if (MapUtil.isGdMapInstalled()) {
                    PositionConvertUtil positionConvertUtil = new PositionConvertUtil();
                    CoordinateBean coordinateBean = positionConvertUtil.wgs84ToGcj02(lat, lng);
                    MapUtil.openGaoDeNavi(WorkActivity.this, 0, 0, null, coordinateBean.getLatitude(), coordinateBean.getLongitude(), "");
                } else {
                    Toast.makeText(WorkActivity.this, "你没安装高德地图", Toast.LENGTH_SHORT).show();
                }
            }
        });
        btn_zpb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(WorkActivity.this, PhotoFormActivity.class);
                intent.putExtra("point", Point);
                intent.putExtra("lat",lat);
                intent.putExtra("lng",lng);
                startActivity(intent);
            }
        });
        iv_yj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(Point.getPanorama() != null && !Point.getPanorama().equals("")){
                    Ablum.imageMax(UserUtil.address+Point.getPanorama(), WorkActivity.this,false);
                }
            }
        });
        iv_zj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(Point.getBust() != null && !Point.getBust().equals("")){
                    Ablum.imageMax(UserUtil.address+Point.getBust(), WorkActivity.this,false);
                }
            }
        });
        iv_jj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(Point.getCloseup() != null && !Point.getCloseup().equals("")){
                    Ablum.imageMax(UserUtil.address+Point.getCloseup(), WorkActivity.this,false);
                }

            }
        });

    }

    private void initView() {
        this.iv_yj=findViewById(R.id.iv_yj);
        this.iv_zj=findViewById(R.id.iv_zj);
        this.iv_jj=findViewById(R.id.iv_jj);
        this.tv_pointID = findViewById(R.id.tv_pointID);
        this.tv_name = findViewById(R.id.tv_name);
        this.tv_status = findViewById(R.id.tv_status);
        this.btn_zpb = findViewById(R.id.btn_zpb);
        this.btn_nav = findViewById(R.id.btn_nav);

        SharedPreferences sharedPreferences = getSharedPreferences("PuCha", Context.MODE_PRIVATE);
        token = sharedPreferences.getString("token", null);
    }

}
